<%--
  Created by IntelliJ IDEA.
  User: 王志斌
  Date: 2019/1/30
  Time: 16:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    String static_path = path + "/static/X-admin-2.3";
%>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加部门</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="<%=static_path%>/css/font.css">
    <link rel="stylesheet" href="<%=static_path%>/css/xadmin.css">
    <script type="text/javascript" src="<%=static_path%>/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="<%=static_path%>/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=static_path%>/js/xadmin.js"></script>

    <!-- ueditor--配置文件 -->
    <script type="text/javascript" src="<%=path%>/static/ueditor/ueditor.config.js"></script>
    <!-- ueditor--编辑器源码文件 -->
    <script type="text/javascript" src="<%=path%>/static/ueditor/ueditor.all.js"></script>

</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="department_name" class="layui-form-label">
                <span class="x-red">*</span>部门名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="department_name" required="" lay-verify="required"
                       value="${requestScope.departInfo.departmentName}" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="adminId" class="layui-form-label">
                <span class="x-red">*</span>部门负责人
            </label>
            <div class="layui-input-inline">
                <%--<input type="text" id="intro" name="username" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">--%>

                <input id="adminId" type="text" class="layui-input"
                       data-fv-field="Address" list="send_siteSelect" required="" lay-verify="required" value="${requestScope.departInfo.user.id}">
                <datalist id="send_siteSelect">
                    <c:forEach items="${userList}" var="user">
                        <option value="${user.id}">${user.name}</option>
                    </c:forEach>
                </datalist>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="people_num" class="layui-form-label">
                <span class="x-red">*</span>预期人数
            </label>
            <div class="layui-input-inline">
                <input type="text" id="people_num" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" oninput = "value=value.replace(/[^\d]/g,'')" maxlength="3" value="${requestScope.departInfo.peopleNum}">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label for="department_intro" class="layui-form-label">
                部门简介
            </label>
            <div class="layui-input-block">
                <textarea id="department_intro" class="layui-textarea"
                          maxlength="300" style="width:500px; height:130px;">${requestScope.departInfo.remark}</textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">
                部门制度
            </label>
            <div class="layui-input-block">

                <!-- ueditor在线文本编辑器 -->
                <!-- 加载编辑器的容器 -->
                <script id="container" name="content" type="text/plain">${departRegulation}</script>

                <!-- 实例化编辑器 -->
                <script type="text/javascript">
                    var ue = UE.getEditor('container', {
                        toolbars: [[
                            'undo', //撤销
                            'redo', //重做
                            'bold', //加粗
                            'indent', //首行缩进
                            'italic', //斜体
                            'underline', //下划线
                            'fontborder', //字符边框
                            'formatmatch', //格式刷
                            'source', //源代码
                            'pasteplain', //纯文本粘贴模式
                            'selectall', //全选
                            'print', //打印
                            'preview', //预览
                            'horizontal', //分隔线
                            'cleardoc', //清空文档"
                            'fontfamily', //字体
                            'fontsize', //字号
                            'link', //超链接
                            'emotion', //表情
                            'spechars', //特殊字符
                            'searchreplace', //查询替换
                            'justifyleft', //居左对齐
                            'justifyright', //居右对齐
                            'justifycenter', //居中对齐
                            'justifyjustify', //两端对齐
                            'forecolor', //字体颜色
                            'backcolor', //背景色
                            'rowspacingtop', //段前距
                            'rowspacingbottom', //段后距
                            'imagecenter', //居中
                            'lineheight', //行间距
                            'autotypeset', //自动排版
                        ]],
                        initialFrameWidth:800,
                        initialFrameHeight:200,
                        maximumWords:1000,
                        //关闭字数统计
                        wordCount:false,
                        //关闭elementPath
                        elementPathEnabled:false,
                    });
                </script>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">修改部门</button>
        </div>

    </form>
</div>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;

        //监听提交
        form.on('submit(add)', function(data){
            //console.log(data);
            //发异步，把数据提交
            layer.alert("增加成功", {icon: 6},function () {
                //部门名称
                var department_name = $("#department_name").val();
                //部门负责人
                var adminId = $("#adminId").val();
                //部门编制人数
                var people_num = $("#people_num").val();
                //部门简介
                var department_intro = $("#department_intro").val();
                //获取部门规章制度
                var html = ue.getContent();

                $.ajax({
                    url:"<%=path%>/manage/department/update",
                    type:"post",
                    data:{departmentName:department_name,"user.id":adminId,peopleNum:people_num,remark:department_intro,html:html,id:${requestScope.departInfo.id}},
                });

                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);

                //子窗口关闭后由父窗口调用刷新
                //window.parent.location.reload();
            });
            return false;
        });


    });




</script>
</body>
</html>